A powerful tool that converts Mermaid diagrams from markdown files to high-quality PNG images. This tool provides both a Python script version and a standalone executable that includes embedded Node.js runtime for offline use.
Install prerequisites:
# Install Node.js and npm
npm install -g @mermaid-js/mermaid-cli
Run the converter:
python mermaid_to_png_converter.py example_document.md
Build the standalone executable:
python build_standalone.py
Use the generated executable:
./mermaid_to_png_converter example_document.md
npm install -g @mermaid-js/mermaid-cli)# Clone the repository
git clone https://github.com/jimmywong2003/MermaidToPNG.git
cd MermaidToPNG
# Build the standalone executable
python build_standalone.py
The build process will:
mermaid_to_png_converter <markdown_file.md>
# Convert diagrams in a specific file
mermaid_to_png_converter example_document.md
# Convert diagrams in all markdown files (Unix/Linux/macOS)
for file in *.md; do
mermaid_to_png_converter "$file"
done
# Convert diagrams in all markdown files (Windows)
for %f in (*.md) do mermaid_to_png_converter "%f"
Mermaid to PNG Converter - Standalone Version
==================================================
Processing: example_document.md
✓ Node.js runtime available
Found 3 mermaid diagram(s)
✓ Successfully converted example_document_diagrams/diagram_1.mmd to example_document_diagrams/diagram_1.png
✓ Successfully converted example_document_diagrams/diagram_2.mmd to example_document_diagrams/diagram_2.png
✓ Successfully converted example_document_diagrams/diagram_3.mmd to example_document_diagrams/diagram_3.png
Conversion complete: 3/3 diagrams converted successfully
Diagrams saved in: example_document_diagrams/
example_document.md
example_document.md
example_document_diagrams/
├── diagram_1.mmd # Extracted Mermaid code
├── diagram_1.png # Generated PNG image
├── diagram_2.mmd
└── diagram_2.png
Your markdown file should contain Mermaid diagrams wrapped in code blocks:
# Example Document
Some text content...
```mermaid
graph TD
A[Start] --> B{Decision}
B -->|Yes| C[Process 1]
B -->|No| D[Process 2]
C --> E[End]
D --> E
```
More content...
```mermaid
sequenceDiagram
participant User
participant System
User->>System: Request
System->>System: Process
System-->>User: Response
```
graph TD, graph LR)sequenceDiagram)classDiagram)stateDiagram)gantt)pie)requirementDiagram)MermaidToPNG/
├── mermaid_to_png_converter.py # Python script version
├── mermaid_to_png_converter_standalone.py # Standalone version script
├── build_standalone.py # Build script for standalone executable
├── install_mermaid_cli.bat # Windows installation script
├── install_mermaid_cli.sh # Linux/macOS installation script
├── LICENSE # MIT License
├── .gitignore # Git ignore patterns
└── README.md # This file
"Node.js runtime not available"
"mermaid-cli not found"
npm install -g @mermaid-js/mermaid-cliTimeout errors
Blank PNG files
For troubleshooting, you can modify the scripts to add debug output or increase timeouts.
Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests.
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE file for details.
For issues or questions:
Note: The standalone version includes an embedded Node.js runtime, making it larger than the Python script version but completely self-contained.